<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/3/12/012
 * Time: 11:20
 */

namespace app\project\controller;


use app\api\controller\Notice;
use app\common\controller\Common;
use app\project\service\AdvancePlanService;
use think\Controller;
use think\Db;
use think\Exception;
use think\Session;
use think\Validate;

class Figure extends Controller
{
    private $pro_id = 0;
    public function _initialize()
    {
        $swidthStyle = Session::get("style");
        $this->assign("swidthStyle",$swidthStyle);
        $pro_id = empty($_GET['pro_id'])?0: $_GET['pro_id'];
        $this->assign("pro_id",$pro_id);

        $library = empty($_GET['library'])?0:$_GET['library'];
        $this->assign("library",$library);
    }


    /**
     * 形象进度
     */
    public function index(){
        $common = new Common();
        //查询项目
        $detail = $common->public_select("project_pro",['id'=>$_GET['pro_id']])->find();
        $this->assign("detail",$detail);
        if(!empty($_GET['keyword'])){
            $keyword = $_GET['keyword'];
            $where['title'] = ['like',"%{$keyword}%"];
        }
        if(!empty($_GET['type'])){
            try {
                $page = empty($_GET['page']) ? 1 : $_GET['page'];
                $limit = empty($_GET['limit']) ? 10 : $_GET['limit'];
                $start = ($page - 1) * $limit;

                $where['pro_id'] = $_GET['pro_id'];
                $list = $common->public_select("project_pro_figure",$where,null,$start,$limit)->order("id desc")->select();
                $count = $common->public_select("project_pro_figure",$where)->count();
                $black['code'] = 0;
                $black['data'] = $list;
                $black['count'] = $count;
            } catch (Exception $e) {
                $black['code'] = 202;
                $black['msg'] = $e->getMessage();
            }
            return $black;
        }
        return $this->fetch("index");
    }

    /**
     * 形象进度视图
     */
    public function detail(){
        $common = new Common();
        if(!empty($_GET['id'])){
            $id = $_GET['id'];
            $detail = $common->public_select("project_pro_figure",['id'=>$id])->find();
            $detail['images'] = explode(";",$detail['images']);
            $this->assign('detail',$detail);
        }
        $template = empty($_GET['id'])?"addView":"saveView";
        return $this->fetch($template);
    }

    //形象进度详情
    public function showView(){
        $common = new Common();
        $id = $_REQUEST['id'];
        $detail = $common->public_select("project_pro_figure",['id'=>$id])->find();
        if(!empty($detail['images'])){
           $detail['images'] = explode(";",$detail['images']);
        }

        //企业状况
        $condition = [1=>"运行正常企业",2=>"一般困难企业",3=>"特别困难企业",4=>"停产企业"];
        //查询问题类型
        $where['status'] = 1;
        $where['pid'] = 0;
        $where['type'] = 6;
        $problem = $common->public_select("project_type",$where,"id,name")->order("sort desc,id desc")->select();
        $problem = array_column($problem,'name',"id");
        $detail['condition_val'] = empty($condition[$detail['condition_val']])?"":$condition[$detail['condition_val']];
        $detail['problem'] = empty($problem[$detail['problem_id']])?"":$problem[$detail['problem_id']];

        $solution = \think\Config::get("solution");
        $detail['solution'] = empty($solution[$detail['solution']])?"":$solution[$detail['solution']];


        $this->assign('detail',$detail);
        return view("showView");
    }

    /**
     * 添加
     * @return mixed
     */
    public function add(){
        $thisWechat = Session::get("thisWechat");
        $data = $this->request->post();
        $common = new Common();
        try{
            $this->condition($data);
            if(!empty($data['images'])){
                $data['images'] = implode(';',$data['images']);
            }
            $data['addtime'] = date("Y-m-d h:i:s",time());
            $data['add_id'] = Session::get("id");
            $title = $common->public_select("project_pro",['id'=>$data['pro_id']])->value("title");
            $id = $common->handle("project_pro_figure",$data,1);
            $log['remark'] = "【工程管理】用户【" . Session::get("user_name") . "】添加项目【'.$title.'】形象进度,关联id【" . $id . "】";
            $common->addLog($log);
            $black['code'] = 0;
            $black['msg'] = "添加成功";
        }catch (Exception $e){
            Db::rollback();
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return $black;
    }

    /**
     * 修改
     * @return mixed
     */
    public function save(){
        $thisWechat = Session::get("thisWechat");
        $data = $this->request->post();
        $common = new Common();
        try{
            $this->condition($data);
            if(!empty($data['images'])){
                $data['images'] = implode(';',$data['images']);
            }else{
                $data['images'] = null;
            }
            
            if(!empty($data['show_time'])){
                if (!$this->checkDateFormat($data['show_time'])) {
                    throw new Exception("时间格式有误");
                }
            }
            
            
            $data['updatetime'] = date("Y-m-d h:i:s",time());
            $data['update_id'] = Session::get("id");
            $title =  $common->public_select("project_pro",['id'=>$data['pro_id']])->value("title");
            $common->handle(  "project_pro_figure",$data,1);
            $log['remark'] = "【工程管理】用户【" . Session::get("user_name") . "】更新项目【'.$title.'】形象进度,关联id【" . $data['id'] . "】";
            $common->addLog($log);
            $black['code'] = 0;
            $black['msg'] = "添加成功";
        }catch (Exception $e){
            Db::rollback();
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return $black;
    }


    public function checkDateFormat($date)
    {
        $dateFormat = 'Y-m-d H:i:s';
        $dateObj = \DateTime::createFromFormat($dateFormat, $date);
        return $dateObj && $dateObj->format($dateFormat) === $date;
    }
    /**
     * 删除
     */
    public function del(){
        try{
            $common = new Common();
            $config = $common->selconfig();
            $id = $_POST['id'];
            $list = Db::connect($config)->name("project_pro_figure")->alias("a")
                ->join("project_pro b","a.pro_id = b.id")->where(['a.id'=>['in',$id]])
                ->field("b.title,a.id")->select();
            $res = $common->public_select("project_pro_figure",['id'=>['in',$id]])->delete();
            if(empty($res)){
                throw new Exception("删除失败");
            }
            foreach ($list as $k=>$v){
                $log['remark'] = "【工程管理】,账号【" . Session::get("user_name") . "】删除项目【".$v['title']."】形象进度,关联id【" . $v['id'] . "】";
                $common->addLog($log);
            }
            $black['code'] = 0;
            $black['msg'] = "删除成功";
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return $black;
    }


    /**
     * @param $data
     */
    public function condition($data){
        $rule = [
            ["title", "require", "项目名称不能为空"],
            ["content", "require", "主要建设内容不能为空"],
        ];
        $validate = new Validate($rule);
        if (!$validate->check($data)) {
            throw new Exception($validate->getError());
        }
    }


    //更新签约状态视图
    public function signView(){
        //查询项目是否存在
        $id = $_REQUEST['id'];
        $common = new Common();
        $where['id'] = $id;
        $assign['detail'] = $common->public_select("project_pro",$where)->find();
        //更新值
        $library = empty($_REQUEST['library'])?0:$_REQUEST['library'];
        $assign['library'] = $library;
        $this->assign($assign);
        return view("signView");
    }


    //更新开工状态视图
    public function startView(){
        //查询项目是否存在
        $id = $_REQUEST['id'];
        $common = new Common();
        $where['id'] = $id;
        $assign['detail'] = $common->public_select("project_pro",$where)->find();
        //更新值
        $library = empty($_REQUEST['library'])?0:$_REQUEST['library'];
        $assign['library'] = $library;

        //项目分组
        $pro_group = \think\Config::get("pro_group");
        $assign['pro_group'] = $pro_group;
        $this->assign($assign);
        return view("startView");
    }

    //更新开工状态视图
    public function replyView(){
        //查询项目是否存在
        $id = $_REQUEST['id'];
        $common = new Common();
        $where['id'] = $id;
        $assign['detail'] = $common->public_select("project_pro",$where)->find();
        //更新值
        $library = empty($_REQUEST['library'])?0:$_REQUEST['library'];
        $assign['library'] = $library;
        $this->assign($assign);
        return view("replyView");
    }

    //更新入库状态视图
    public function warehousingView(){
        //查询项目是否存在
        $id = $_REQUEST['id'];
        $common = new Common();
        $where['id'] = $id;
        $assign['detail'] = $common->public_select("project_pro",$where)->find();
        //更新值
        $library = empty($_REQUEST['library'])?0:$_REQUEST['library'];
        $assign['library'] = $library;
        $this->assign($assign);
        return view("warehousingView");
    }

    //更新状态视图
    public function updateView(){
        //查询项目是否存在
        $id = $_REQUEST['id'];
        $common = new Common();
        $where['id'] = $id;
        $assign['detail'] = $common->public_select("project_pro",$where)->find();
        //更新值
        $library = empty($_REQUEST['library'])?0:$_REQUEST['library'];
        $assign['library'] = $library;
        $this->assign($assign);
        return view("updateView");
    }

    //更新项目状态(开工库)
    public function replyStatus(){
        //查询项目是否存在
        $id = $_REQUEST['id'];
        $common = new Common();
        $where['id'] = $id;
        $assign['detail'] = $common->public_select("project_pro",$where)->find();
        //更新值
        $library = empty($_REQUEST['library'])?0:$_REQUEST['library'];
        $assign['library'] = $library;

        //项目分组
        $pro_group = \think\Config::get("pro_group");
        $assign['pro_group'] = $pro_group;
        $this->assign($assign);
        return view("replyStatus");
    }


    //执行状态更新
    public function updateDo(){
        try{
            $common = new Common();
            $data = $this->request->post();

            switch ($data['type']){
                case '0':
//                    if(!empty($_POST['project_status'])){
//                        $rule = [
//                            ["remark", "require", "问题内容不能为空"],
//                        ];
//                        $validate = new Validate($rule);
//                        if (!$validate->check($data)) {
//                            throw new Exception($validate->getError());
//                        }
//                    }
                    //提醒责任人
                    if(!empty($_POST['project_status'])){
                        $project_status = ["待开工","逾期","已竣工","暂缓推进","基础开工","主体开工"];
                        $addComment['pro_id'] = $data['id'];
                        $addComment['title'] = $project_status[$_POST['project_status']];
                        $addComment['content'] = $data['remark'];
                        $addComment['addtime'] = date("Y-m-d H:i:s");
                        $addComment['add_id'] =  Session::get("id");
                        $addComment['type'] = 1;
                        $common->handle("project_pro_comment",$addComment,1);
                        //逾期通知
                        if($_POST['project_status']==1){
                            $notice = new Notice();
                            $notice->copyMessage(Session::get("user_name"),$addComment);
                        }
                    }
                    //提醒责任人

                    //更改项目状态
                    $where['id'] = $data['id'];
                    $update['project_status'] = $_POST['project_status'];
                    $common->public_select("project_pro",$where)->update($update);

                    //记录项目更新日志
                    $insertData['pro_id'] = $data['id'];
                    $insertData['remark'] = $data['remark'];
                    $insertData['project_status'] = $data['project_status'];
                    $insertData['addtime'] = date("Y-m-d H:i:s");
                    $insertData['add_id'] = Session::get("id");
                    $common->handle("project_pro_log",$insertData,1);
                    break;
                case 'project_status':
                    //更改项目状态
                    $where['id'] = $data['id'];
                    $update['project_status'] = $_POST['project_status'];
                    if(!empty($_POST['pro_group'])){
                        $update['pro_group'] = $_POST['pro_group'];
                    }
                    $common->public_select("project_pro",$where)->update($update);
                    //记录项目更新日志
                    $insertData['pro_id'] = $data['id'];
                    $insertData['remark'] = $data['remark'];
                    $insertData['project_status'] = $data['project_status'];
                    $insertData['addtime'] = date("Y-m-d H:i:s");
                    $insertData['add_id'] = Session::get("id");
                    $common->handle("project_pro_log",$insertData,1);

                    //已竣工项目转入培育库 工业企业
                    if( $_POST['project_status']==1){
                        $copyDate = $common->public_select("project_pro",$where)->find();
                        $copyWhere['library'] = 6;
                        $copyWhere['pid'] = empty($copyDate['pid'])?$copyDate['id']:$copyDate['pid'];
                        $copyId = $common->public_select("project_pro",$copyWhere)->value('id');
                        if(empty($copyId)){
                            unset($copyDate['id']);
                            $copyDate['library'] = 6;
                            $copyDate['menuTop'] = 1;
                            $copyDate['enterprise'] = 55;
                            $copyDate['addtime'] = date("Y-m-d H:i:s");
                            $copyDate['add_id'] = Session::get("id");
                            $copyDate['pid'] = empty($copyDate['pid'])?$copyDate['id']:$copyDate['pid'];
                            $common->handle("project_pro",$copyDate,1);
                        }
                    }





                    break;
                default:
                    //更改项目签约状态
                    $where['id'] = $data['id'];
                    if(!empty($_POST['sign'])){
                        $update['sign'] = $_POST['sign'];
                        $nowValue = $_POST['sign'];
                        $library_v = 2;
                    }
                    if(!empty($_POST['start_status'])){
                        $update['start_status'] = $_POST['start_status'];
                        $nowValue = $_POST['start_status'];
                        $library_v = 3;
                    }

                    if(!empty($_POST['pro_group'])){
                        $update['pro_group'] = $_POST['pro_group'];
                    }

                    if(!empty($_POST['warehousing'])){
                        $update['warehousing'] = $_POST['warehousing'];
                        $nowValue = $_POST['warehousing'];
                        $nowValue = 1;
                        $library_v = 5;
                    }

                    if(!empty($_POST['reply'])){
                        $update['reply'] = $_POST['reply'];
                        $nowValue = 2;
                        $library_v = 6;
                    }

                    if(!empty($_POST['actualsignTime'])){
                        $update['actualsignTime'] = $_POST['actualsignTime'];
                    }
                    if(!empty($_POST['adopt'])){
                        $update['adopt'] = $_POST['adopt'];
                    }
                    $is_copy = empty($_POST['is_copy'])?0:$_POST['is_copy'];
                    if($nowValue == 2){
                        //招商签约库里面已签约的项目就转入到项目预备库
                        $detail = $common->public_select("project_pro",$where,"id,pid,library")->find();
                        if($library_v!=6){
                            //复制该项目
                            $copyWhere['library'] = $library_v;
                            $copyWhere['pid'] = empty($detail['pid'])?$detail['id']:$detail['pid'];
                            $copyId = $common->public_select("project_pro",$copyWhere)->value('id');
                            if(empty($copyId)){
                                $copyDate = $common->public_select("project_pro",$where)->find();
                                if(!empty($copyDate)){
                                    unset($copyDate['id']);
                                    $copyDate['library'] = $library_v;
                                    $copyDate['addtime'] = date("Y-m-d H:i:s");
                                    $copyDate['add_id'] = Session::get("id");
                                    $copyDate['pid'] = empty($detail['pid'])?$detail['id']:$detail['pid'];
                                    $common->handle("project_pro",$copyDate,1);
                                }
                            }

                            if($is_copy==1){
                                unset($copyWhere);
                                $copyWhere['library'] = 4;
                                $copyWhere['pid'] = empty($detail['pid'])?$detail['id']:$detail['pid'];
                                $copyId = $common->public_select("project_pro",$copyWhere)->value('id');
                                if(empty($copyId)){
                                    unset($copyDate);
                                    $copyDate = $common->public_select("project_pro",$where)->find();
                                    if(!empty($copyDate)){
                                        unset($copyDate['id']);
                                        $copyDate['library'] = 4;
                                        $copyDate['plan_category'] = 2;

                                        if(!empty($_POST['actualsignTime'])){
                                            $actualsignTime = $copyDate['actualsignTime'] = $_POST['actualsignTime'];


                                        }

                                        $copyDate['addtime'] = date("Y-m-d H:i:s");
                                        $copyDate['add_id'] = Session::get("id");
                                        $copyDate['pid'] = empty($detail['pid'])?$detail['id']:$detail['pid'];
                                        $common->handle("project_pro",$copyDate,1);


                                        if(!empty($_POST['actualsignTime'])){
                                            $array = [343,344,350];
                                            $plantime[0] = date("Y-m-d",strtotime("+3 Month",strtotime($actualsignTime)));
                                            $plantime[1] = date("Y-m-d",strtotime("+7 Month",strtotime($actualsignTime)));
                                            $plantime[2] = date("Y-m-d",strtotime("+31 Month",strtotime($actualsignTime)));
                                            //推进计划更新
                                            foreach ($array as $k=>$v){
                                                unset($advdata);
                                                $advdata['pro_id'] = empty($detail['pid'])?$detail['id']:$detail['pid'];
                                                $advdata['type_id'] = $v;
                                                $advDetail = AdvancePlanService::detailService($advdata);
                                                $advdata['id'] = empty($advDetail)?0:$advDetail['id'];
                                                $advdata['time'] = $plantime[$k];
                                                $advdata['color'] = 0;
                                                AdvancePlanService::saveService($advdata);
                                            }
                                        }

                                    }
                                }
                            }

                        }
                        /*if(!strstr($library,"'{$library_v}'")){
                            $library  = $library.",".$library_v;
                        }
                        $update['library'] = $library;*/
                    }else{
                        $copyWhere['library'] = $library_v;
                        $copyWhere['pid'] = $data['id'];;
                        $common->public_select("project_pro",$copyWhere)->delete();
                        /*$library = $common->public_select("project_pro",$where)->value("library");
                        $library = explode(",",$library);
                        foreach ($library as $k=>$v){
                            if($v==$library_v){
                                unset($library[$k]);
                            }
                        }
                        $library = implode(",",$library);
                        $update['library'] = $library;*/
                    }


                    $common->public_select("project_pro",$where)->update($update);

                    //提醒责任人
                    $addComment['pro_id'] = $data['id'];
                    if(!empty($_POST['sign'])){

                        $sign = [1=>"待签约",2=>"已签约",3=>"已逾期",4=>"暂缓推进",5=>"在谈项目"];
//                        $addComment['title'] = ($_POST['sign']==2)?"已签约":"未签约";
                        $addComment['title'] = $sign[$_POST['sign']];
                        $insertData['sign'] = $data['sign'];
                    }
                    if(!empty($_POST['start_status'])){
                        $sign = [1=>"待开工",2=>"已开工",3=>"已逾期",4=>"已终止"];
//                        $addComment['title'] = ($_POST['start_status']==2)?"已开工":"未开工";
                        $addComment['title'] = $sign[$_POST['start_status']];
                        $insertData['sign'] = $data['start_status'];
                    }
                    if(!empty($_POST['warehousing'])){
                        $addComment['title'] = ($_POST['warehousing']==2)?"已入库":"未入库";
                        $insertData['sign'] = $data['warehousing'];
                    }
                    if(!empty($_POST['reply'])){
//                        $replyArray = [1=>"正在申报",2=>"申报退回",3=>"成功申报"];
                        $replyArray = [1=>"已启报",2=>"已报竭"];
                        $addComment['title'] = $replyArray[$_POST['reply']];
//                        $addComment['title'] = ($_POST['reply']==2)?"已启报":"未启报";
                        $insertData['sign'] = $data['reply'];
                    }
                    $addComment['content'] = $data['remark'];
                    $addComment['addtime'] = date("Y-m-d H:i:s");
                    $addComment['add_id'] =  Session::get("id");
                    $addComment['type'] = 1;
                    $common->handle("project_pro_comment",$addComment,1);
                    //提醒责任人

//                    $notice = new Notice();
//                    $notice->copyMessage(Session::get("user_name"),$addComment);

                    //记录项目更新日志
                    $insertData['pro_id'] = $data['id'];
                    $insertData['remark'] = $data['remark'];
                    $insertData['addtime'] = date("Y-m-d H:i:s");
                    $insertData['add_id'] = Session::get("id");
                    $insertData['type'] = $data['type'];
                    $common->handle("project_pro_log",$insertData,1);
                    break;

            }

            $black['code'] = 0;
            $black['msg'] = "操作成功";
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return $black;
    }

    //更新日志
    public function updateLog(){
        $id = $_REQUEST['id'];
        $common = new Common();
        $where['id'] = $id;
        $assign['detail'] = $common->public_select("project_pro",$where)->find();
        $assign['pro_id'] = $id;
        $this->assign($assign);
        if(!empty($_GET['type'])){
            try {
                $page = empty($_GET['page']) ? 1 : $_GET['page'];
                $limit = empty($_GET['limit']) ? 10 : $_GET['limit'];
                $start = ($page - 1) * $limit;

                $where1['pro_id'] = $_REQUEST['id'];
                $where1['type'] = 0;
                $list = $common->public_select("project_pro_log",$where1,null,$start,$limit)->order("id desc")->select();

                foreach ($list as $k=>$v){
                    $list[$k]['project_status'] = empty($v['project_status'])?"正常":"逾期";
                }
                $count = $common->public_select("project_pro_log",$where1)->count();
                $black['code'] = 0;
                $black['data'] = $list;
                $black['count'] = $count;
            } catch (Exception $e) {
                $black['code'] = 202;
                $black['msg'] = $e->getMessage();
            }
            return $black;
        }
        return view("updateLog");
    }


    //固投信息
    public function fixedDetail(){
        $common = new Common();
        $id = $_POST['id'];
        $taxableIncome = isset($_POST['type']) ? $_POST['type'] : '';
        //总投资额
        $assign['detail'] = $detail =  $common->public_select("project_pro",['id'=>$id])->find();
        //查询该报表是否存在
        $assign['form'] = $form = $common->public_select("project_pro_form",['pro_id'=>$id])->find();

        //已完成投资
        $arr = ['year_val','january_february','march','april','may','june','july','august','september','october','november','december'];
        $invested = 0;
        foreach ($arr as $item){
            if(!empty($form[$item])){
                $invested+=$form[$item];
            }
        }
        $investment = empty($detail['investment'])?0:$detail['investment'];
        $percentage = 0;
        if(intval($investment)){
            $percentage = round(($invested/$investment)*100,2);
        }

        $assign['invested'] = $invested;
        $assign['percentage'] = $percentage;
        $assign['investment'] = $investment;


        $this->assign($assign);
        if ($taxableIncome == 'taxableIncome') {
            return view("taxableIncome");
        }
        return view("fixedDetail");
    }

    //更新固投信息
    public function fixedApi(){
        $common = new Common();
        try {
            $id = $_POST['pro_id'];
            //查询该报表是否存在
            $data = $this->request->post();
            $detail_id = $common->public_select("project_pro_form",['pro_id'=>$id])->value("id");
            if(!empty($detail_id)){
                $data['id'] = $detail_id;
            }
            $common->handle("project_pro_form",$data,1);
            $black['code'] = 0;
            $black['msg'] = "操作成功";
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return $black;
    }

    //应税收入
    public function taxRevenueDetail(){
        $common = new Common();
        $id = $_POST['id'];
        $year = date('Y', time());
        //总投资额
        $assign['detail'] = $detail =  $common->public_select("project_pro",['id'=>$id])->find();
        //查询该报表是否存在
        $form = $common->public_select("project_pro_tax_revenue",['pro_id'=>$id,'year'=>$year])->find();

        if ($form) {
            foreach ($form as &$value) {
                if ($value == 0) {
                    $value = null;
                }
            }
            unset($value);
        }


        $assign['form'] = $form;
//        //已完成投资
//        $arr = ['year','january', 'february','march','april','may','june','july','august','september','october','november','december'];

        $this->assign($assign);
        return view("taxableIncome");
    }

    //更新应税收入
    public function taxRevenueApi(){
        $common = new Common();
        try {
            $id = $_POST['pro_id'];
            //查询该报表是否存在
            $data = $this->request->post();
            $detail_id = $common->public_select("project_pro_tax_revenue",['pro_id'=>$id])->value("id");
            if(!empty($detail_id)){
                $data['id'] = $detail_id;
            }
            $year = date('Y', time());
            $data['year'] = $year;
            $common->handle("project_pro_tax_revenue",$data,1);
            $black['code'] = 0;
            $black['msg'] = "操作成功";
        }catch (Exception $e){
            $black['code'] = 202;
            $black['msg'] = $e->getMessage();
        }
        return $black;
    }

    public function planDetail(){
        $pro_id = $_GET['pro_id'];
        $this->assign("pro_id",$pro_id);

        //查询本年都节点计划
        $year = date("Y");
        $common = new Common();
        $where['plan_title'] = $year;
        $where['pro_id'] = $pro_id;
        $detail = $common->public_select("project_pro_plan",$where)->order("id desc")->find();
        $this->assign("detail",$detail);
        return $this->fetch("planDetail");
    }

    public function planApi(){
        $year = $_POST['year'];
        $pro_id = $_POST['pro_id'];
        $common = new Common();
        $where['plan_title'] = $year;
        $where['pro_id'] = $pro_id;
        $detail = $common->public_select("project_pro_plan",$where)->order("id desc")->find();
        return $detail;
    }


}